#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2505;

int k, n;
int s[N], p[N], sz[N];
ll now;
vector<int> ch[N];
ll dp[N][N];
void dfs(int u) {
  rep(i, 1, k + 1) dp[u][i] = -1e18;
  sz[u] = 1;
  dp[u][1] = p[u] - now * s[u];
  for (int v : ch[u]) {
    dfs(v);
    sz[u] += sz[v];
    per(i, min(k + 1, sz[u]), 2) {
      rep(j, 1, min(i - 1, sz[v])) dp[u][i] =
          max(dp[u][i], dp[u][i - j] + dp[v][j]);
    }
  }
}
bool check(int x) {
  now = x;
  dfs(0);
  return dp[0][k + 1] >= 0;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> k >> n;
  rep(i, 1, n) {
    int r;
    cin >> s[i] >> p[i] >> r;
    p[i] *= 100000;
    ch[r].push_back(i);
  }
  int l = 1, h = 1e9;
  while (l <= h) {
    int mid = (l + h) >> 1;
    if (check(mid))
      l = mid + 1;
    else
      h = mid - 1;
  }
  cout << fixed << setprecision(3) << (l - 1) / 100000.0;
  return 0;
}